<html>
<head><meta charset="utf-8"><title>Get inner span, not outer span · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html">Get inner span, not outer span</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222233464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222233464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222233464">(Jan 10 2021 at 18:10)</a>:</h4>
<p>For <a href="https://github.com/rust-lang/rust/pull/80339">https://github.com/rust-lang/rust/pull/80339</a>, I'm trying to calculate spans on demand instead of special casing them in rustdoc. The current CI failure is</p>
<div class="codehilite"><pre><span></span><code>std/primitive.slice.html:1416: broken link - src/core/slice/ascii.rs.html
</code></pre></div>
<p>which happens because the new spans are outer spans, not inner spans:</p>
<div class="codehilite"><pre><span></span><code>418452:DEBUG rustdoc::html::sources considering item DefId(0:7186 ~ core[8787]::slice::ascii) with span Span(library/core/src/slice/mod.rs:30:1: 30:11 (#0))
</code></pre></div>
<p>Is there a way to tell <code>def_span</code> to give me the inner span instead? Or is that already the default behavior and I'm confusing myself?</p>
<p>Here's my implementation of <code>span()</code> for <code>clean::Item</code>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">ItemKind</span>::<span class="n">ModuleItem</span><span class="p">(</span><span class="n">Module</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">override_span</span>: <span class="nb">Some</span><span class="p">(</span><span class="n">span</span><span class="p">),</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">})</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;*</span><span class="bp">self</span><span class="p">.</span><span class="n">kind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="o">*</span><span class="n">span</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">is_fake</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="n">Span</span>::<span class="n">dummy</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">sp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">def_id</span><span class="p">.</span><span class="n">as_local</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Some</span><span class="p">(</span><span class="n">local</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">hir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">hir</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">hir</span><span class="p">.</span><span class="n">span_with_body</span><span class="p">(</span><span class="n">hir</span><span class="p">.</span><span class="n">local_def_id_to_hir_id</span><span class="p">(</span><span class="n">local</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="nb">None</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">def_span</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="n">def_id</span><span class="p">),</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>
<span class="n">Span</span>::<span class="n">from_rustc_span</span><span class="p">(</span><span class="n">sp</span><span class="p">)</span><span class="w"> </span><span class="c1">// this is just calling `source_callsite()`</span>
</code></pre></div>



<a name="222233715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222233715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222233715">(Jan 10 2021 at 18:16)</a>:</h4>
<p>the really frustrating thing is I haven't been able to reproduce the failures on anything smaller than <code>core</code></p>



<a name="222234022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222234022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222234022">(Jan 10 2021 at 18:24)</a>:</h4>
<p>oh I take it back, I came up with an MCVE:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// lib.rs</span>
<span class="k">mod</span> <span class="nn">span</span><span class="p">;</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>
<span class="c1">// span.rs</span>
<span class="k">impl</span><span class="w"> </span><span class="k">crate</span>::<span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>that shows <code>[src]</code> for <code>fn f</code> on nightly, and the whole file is missing with my changes</p>



<a name="222234201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222234201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222234201">(Jan 10 2021 at 18:28)</a>:</h4>
<p>I don't understand the issue. Which is the span you want, and which one do you actually get?</p>



<a name="222234421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222234421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222234421">(Jan 10 2021 at 18:33)</a>:</h4>
<p>I want a span pointing to <a href="https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/library/core/src/slice/ascii.rs#L1">https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/library/core/src/slice/ascii.rs#L1</a>. Instead I get a span pointing to <a href="https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/library/core/src/slice/mod.rs#L30">https://github.com/rust-lang/rust/blob/fd34606ddf02d1e9364e459b373a6ad665c3d8a4/library/core/src/slice/mod.rs#L30</a>.</p>



<a name="222235149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222235149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222235149">(Jan 10 2021 at 18:51)</a>:</h4>
<p>In your PR, I don't understand why you need to special-case ModuleItem. The former version did not, dit it?</p>



<a name="222235444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222235444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222235444">(Jan 10 2021 at 18:59)</a>:</h4>
<p>The former version special case them: <a href="https://github.com/rust-lang/rust/pull/80339/files#diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9L249">https://github.com/rust-lang/rust/pull/80339/files#diff-384affc1b4190940f114f3fcebbf969e7e18657a71ef9001da6b223a036687d9L249</a></p>



<a name="222235544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20inner%20span%2C%20not%20outer%20span/near/222235544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20inner.20span.2C.20not.20outer.20span.html#222235544">(Jan 10 2021 at 19:01)</a>:</h4>
<p>I <em>thought</em> I was preserving the same behavior but apparently not</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>